feat(fitfunctions): add hinge, composite, and Heaviside fit functions#422
feat(fitfunctions): add hinge, composite, and Heaviside fit functions#422blalterman merged 10 commits intomasterfrom
Conversation
…tion=True The exception handler on line 813 only caught RuntimeError and ValueError, but FitFailedError (raised by _run_least_squares when max_nfev exceeded) inherits from FitFunctionError, not RuntimeError. This caused make_fit to raise instead of returning the exception when return_exception=True. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Piecewise linear function with hinge point for modeling saturation behavior: - Rising region: f(x) = m1*(x-x1) where m1 = yh/(xh-x1) - Plateau region: f(x) = m2*(x-x2) where x2 = xh - yh/m2 Parameters: xh (hinge x), yh (hinge y), x1 (x-intercept), m2 (plateau slope) Includes 24 comprehensive tests covering: - Function evaluation (rising, plateau, sloped plateau) - Parameter recovery from clean and noisy data (2σ tolerance) - Initial parameter estimation - Weighted fitting with heteroscedastic noise - Edge cases and error handling Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for TwoLine, Saturation, HingeMin, HingeMax, and HingeAtPoint fit functions. Tests include: - Function evaluation with known parameters - Parameter recovery from clean and noisy data - Derived property consistency (xs, s, theta, m2, x_intercepts) - Continuity at hinge points - Initial guess (p0) estimation - Edge cases and numerical stability Tests written first following TDD - implementations in subsequent commits. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for GaussianPlusHeavySide, GaussianTimesHeavySide, and GaussianTimesHeavySidePlusHeavySide. Tests include: - Function evaluation with known parameters - Parameter recovery from clean and noisy data - Gaussian component behavior (normalization, peak location) - Heaviside step transitions - Component interaction verification - Initial guess (p0) estimation with guess_x0 parameter Tests written first following TDD - implementations in subsequent commits. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for HeavySide fit function. Tests include: - Function evaluation with known parameters - Step transition behavior (x < x0, x == x0, x > x0) - Parameter recovery from clean and noisy data - Initial guess (p0) estimation with optional guess parameters - Edge cases (step at data boundary, flat data) - TeX function representation Tests written first following TDD - implementation in subsequent commit. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add five piecewise linear fit functions for modeling transitions: - TwoLine: Two intersecting lines (minimum), params: x1, x2, m1, m2 - Saturation: Linear rise with saturation plateau, params: x1, xs, s, theta - HingeMin: Minimum of two lines at hinge point, params: m1, x1, x2, h - HingeMax: Maximum of two lines at hinge point, params: m1, x1, x2, h - HingeAtPoint: Piecewise linear with specified hinge point, params: m1, b1, m2, b2 All classes include: - Analytic function definitions using np.minimum/np.maximum - Data-driven initial guess (p0) estimation - Derived properties (xs, s, theta, m2, x_intercepts as applicable) - TeX function representations for plotting Contributed from nh/vanishing_speed_hinge_fits.py with improvements: - Consistent API with existing FitFunction classes - TODO comments for future data-driven p0 estimation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add three composite fit functions combining Gaussian and Heaviside: - GaussianPlusHeavySide: Gaussian + Heaviside step params: x0, y0, y1, mu, sigma, A - GaussianTimesHeavySide: Gaussian × Heaviside step params: x0, mu, sigma, A - GaussianTimesHeavySidePlusHeavySide: (Gaussian × Heaviside) + Heaviside params: x0, y1, mu, sigma, A All classes include: - Analytic function definitions - Data-driven initial guess (p0) estimation - Optional guess_x0 parameter for step location hint - TeX function representations Contributed from nh/vanishing_speed_hinge_fits.py with fixes: - Fixed typo bug: return gaussian_heavy_size -> gaussian_heavy_side - Renamed p0_x0 to guess_x0 for API consistency Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add HeavySide fit function for modeling abrupt transitions: - HeavySide: Step function using np.heaviside params: x0 (transition point), y0 (baseline), y1 (step height) Features: - Analytic function: y1 * H(x0 - x) + y0 - Data-driven initial guess (p0) estimation - Optional guess_x0, guess_y0, guess_y1 parameters - TeX function representation Contributed from nh/vanishing_speed_hinge_fits.py with fixes: - Implemented p0 estimation (original raised NotImplementedError) Also updates __init__.py to export all new classes: - TwoLine, Saturation, HingeMin, HingeMax, HingeAtPoint - GaussianPlusHeavySide, GaussianTimesHeavySide, GaussianTimesHeavySidePlusHeavySide - HeavySide Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @blalterman's task —— View job Code Review CompleteI've completed a comprehensive review of this substantial PR that adds 9 new fit functions to SolarWindPy. Here's my detailed assessment: Review Summary:
Overall Assessment: EXCELLENT ⭐⭐⭐⭐⭐This is a high-quality contribution that demonstrates excellent coding practices and thorough implementation. The PR successfully adds substantial new functionality while maintaining code quality. 🎯 StrengthsCode Architecture & Design
Implementation Quality
Documentation Excellence
Error Handling & Validation# Example of robust handling in hinge.py:117-118
x2 = xh - (yh / m2) if abs(m2) > 1e-15 else np.inf
y2 = m2 * (x - x2) if abs(m2) > 1e-15 else yh * np.ones_like(x)Test Coverage
|
SolarWindPy Documentation Validation - Python 3.11✅ Status: PASSED Essential Metrics:
🎉 All essential documentation examples working! |
Add comprehensive CONTRIBUTING.md for the fitfunctions module covering: - Development workflow (TDD: tests before implementation) - FitFunction class requirements (function, p0, TeX_function) - Data-driven p0 estimation (no hardcoded domain values) - Test categories E1-E7 with tolerance specifications - Test patterns and anti-patterns - Non-trivial test criteria (6 requirements) - Test parameterization for DRY multi-case tests - Quality checklist for PR submissions This standalone document will be integrated into unified project docs once all submodules have contribution standards. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @blalterman's task —— View job Code Review CompleteI've completed a comprehensive review of this substantial PR that adds 9 new fit functions to SolarWindPy. Here's my detailed assessment: Review Tasks:
Overall Assessment: EXCELLENT ⭐⭐⭐⭐⭐This is a high-quality contribution that demonstrates excellent coding practices and thorough implementation. The PR successfully adds substantial new functionality while maintaining code quality. 🎯 StrengthsCode Architecture & Design
Implementation Quality
Documentation Excellence
Error Handling & Validation# Example of robust handling in hinge.py:117-118
x2 = xh - (yh / m2) if abs(m2) > 1e-15 else np.inf
y2 = m2 * (x - x2) if abs(m2) > 1e-15 else yh * np.ones_like(x)Test Coverage
|
SolarWindPy Documentation Validation - Python 3.11✅ Status: PASSED Essential Metrics:
🎉 All essential documentation examples working! |
Fix CI validation failure caused by Black formatting violations in: - solarwindpy/fitfunctions/composite.py (2 line-length issues) - tests/fitfunctions/test_composite.py - tests/fitfunctions/test_heaviside.py - tests/fitfunctions/test_hinge.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Claude finished @blalterman's task —— View job Claude finished @blalterman's task —— View job Code Review CompleteI've completed a comprehensive review of this substantial PR that adds 9 new fit functions to SolarWindPy. Here's my detailed assessment: Review Tasks:
Overall Assessment: EXCELLENT ⭐⭐⭐⭐⭐This is a high-quality contribution that demonstrates excellent coding practices and thorough implementation. The PR successfully adds substantial new functionality while maintaining code quality. 🎯 StrengthsCode Architecture & Design
Implementation Quality
Documentation Excellence
Error Handling & Validation# Example of robust handling in hinge.py:117-118
x2 = xh - (yh / m2) if abs(m2) > 1e-15 else np.inf
y2 = m2 * (x - x2) if abs(m2) > 1e-15 else yh * np.ones_like(x)Test Coverage
|
SolarWindPy Documentation Validation - Python 3.11✅ Status: PASSED Essential Metrics:
🎉 All essential documentation examples working! |
Summary
Details
hinge.py additions (5 classes)
TwoLine: Two intersecting lines using np.minimumSaturation: Linear rise with saturation plateauHingeMin/HingeMax: Min/max of two lines at hinge pointHingeAtPoint: Piecewise linear with specified hinge coordinatescomposite.py (new file, 3 classes)
heaviside.py (new file, 1 class)
Bug fixes during contribution
gaussian_heavy_size→gaussian_heavy_side)Test plan
🤖 Generated with Claude Code